package cn.com.api.controller;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.com.api.entity.ApiSysMessage;
import cn.com.api.mapper.ApiSysMessageMapper;
import cn.com.api.service.ApiSysMessageService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "message/")
public class ApiSysMessageController {
	@Autowired
	private ApiSysMessageService messageService;

	@Transactional
	@RequestMapping(value = "getMessage")
	public void getMessage(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		List<Map<String, Object>> datas = messageService.getMessage();
		SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for(Map<String,Object> m:datas){
			m.put("sys_create_date", date.format(m.get("sys_create_date")));
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put("datas", datas);
		out.print(JsonUtil.object2json(map));
		out.close();
	}
}
